﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ComUIControl
{
    public partial class IconInfoBox : UserControl, INotifyPropertyChanged  
    {
        private Bitmap _image;
        public Bitmap Image
        {
            get
            {
                return _image;
            }
            set
            {
                if (_image != value)
                {
                    pictureBox1.Image = value;
                    _image = value;
                }
            }
        }

        /// <summary>
        /// 统计已拍照片张数
        /// </summary>
        private int _countTakenPhotos = 0;
        [DefaultValue(3)]
        public int CountTakenPhotos
        {
            get
            {
                return _countTakenPhotos;
            }
            set
            {
                if (_countTakenPhotos != value)
                {
                    _countTakenPhotos = value;
                    if (!this.InvokeRequired)
                    {
                        labelInfo.Text = value.ToString();
                    }
                    this.RaisePropertyChanged("CountTakenPhotos");
                    Invalidate();
                }
            }
        }

        /// <summary>
        /// 应拍照片张数（所有）
        /// </summary>
        private int _totalCount = 3;
        [DefaultValue(3)]
        public int TotalCount
        {
            get
            {
                return _totalCount;
            }
            set
            {
                if (_totalCount != value)
                {
                    _totalCount = value;
                    labelTotal.Text = value.ToString();
                    //this.RaisePropertyChanged("TotalCount");
                }
            }
        }

        public IconInfoBox()
        {
            InitializeComponent();
            labelInfo.DataBindings.Add("Text", this, "CountTakenPhotos");
            //labelTotal.DataBindings.Add("Text", this, "TotalCount");
        }

        public delegate void UpdatePropertyDelegate(string strName); 
        public event PropertyChangedEventHandler PropertyChanged;
        private void RaisePropertyChanged(string propertyName)
        {
            if (this.InvokeRequired)
            {
                UpdatePropertyDelegate outdelegate = new UpdatePropertyDelegate(RaisePropertyChanged);
                this.BeginInvoke(outdelegate, new object[] { propertyName });
                return;
            }
            var handler = this.PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
